package com.hwpt.hwaccount.feature.splash;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

import com.hwpt.hwaccount.R;
import com.hwpt.hwaccount.feature.auth.ui.AuthActivity;
import com.hwpt.hwaccount.feature.home.HomeActivity;

/**
 * 引导页Activity，作为MVP中的View层
 */
public class SplashActivity extends AppCompatActivity implements SplashContract.View {

    private static final String TAG = "SplashActivity";
    private SplashContract.Presenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        // 初始化MVP架构
        initMVP();
        
        // 启动Presenter
        presenter.start();
    }

    /**
     * 初始化MVP各层
     */
    private void initMVP() {
        SplashContract.Model model = new SplashModel(getApplicationContext());
        presenter = new SplashPresenter(this, model);
    }

    @Override
    public void navigateToHome() {
        Log.d(TAG, "跳转到首页");
        Intent intent = new Intent(this, HomeActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void navigateToLogin() {
        Log.d(TAG, "跳转到登录页");
        Intent intent = new Intent(this, AuthActivity.class);
        startActivity(intent);
        finish();
    }



    @Override
    public void showError(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
        Log.e(TAG, message);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) {
            presenter.destroy();
        }
    }
}
